Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>2012-09-23 22:50:56 +0400
committerTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>2012-09-23 22:50:56 +0400
commita42ba82f638e481d7fd3c3ed2ba05c331ef6717e (patch)
tree81a2b9221799707b49b74a5df8bb3ff964ba78bd /source/blender/editors/mesh
parent7afbdff1b6c348227e652e1c3071ab7ba7c91c44 (diff)
parenta73dd3476e7d180d3320afc04d218ce22f2f3bfc (diff)
Merged changes in the trunk up to revision 50829.
Conflicts resolved: source/blender/blenloader/intern/readfile.c source/blender/render/intern/source/convertblender.c source/blender/render/intern/source/pipeline.c Also addressed code inconsistency due to changes in the trunk revision 50628 (color management with OCIO) and 50806 (UV project material). OCIO-related changes are marked OCIO_TODO as in some other files modified in revision 50628.
Diffstat (limited to 'source/blender/editors/mesh')
-rw-r--r--source/blender/editors/mesh/editface.c4
-rw-r--r--source/blender/editors/mesh/editmesh_add.c65
-rw-r--r--source/blender/editors/mesh/editmesh_bvh.c4
-rw-r--r--source/blender/editors/mesh/editmesh_knife.c16
-rw-r--r--source/blender/editors/mesh/editmesh_loopcut.c4
-rw-r--r--source/blender/editors/mesh/editmesh_rip.c12
-rw-r--r--source/blender/editors/mesh/editmesh_select.c9
-rw-r--r--source/blender/editors/mesh/editmesh_slide.c8
-rw-r--r--source/blender/editors/mesh/editmesh_tools.c41
-rw-r--r--source/blender/editors/mesh/editmesh_utils.c15
-rw-r--r--source/blender/editors/mesh/mesh_data.c183
-rw-r--r--source/blender/editors/mesh/mesh_intern.h6
-rw-r--r--source/blender/editors/mesh/mesh_ops.c5
-rw-r--r--source/blender/editors/mesh/meshtools.c96
14 files changed, 275 insertions, 193 deletions
diff --git a/source/blender/editors/mesh/editface.c b/source/blender/editors/mesh/editface.c
index 94e10b53b29..a677f1272a3 100644
--- a/source/blender/editors/mesh/editface.c
+++ b/source/blender/editors/mesh/editface.c
@@ -533,8 +533,8 @@ int do_paintface_box_select(ViewContext *vc, rcti *rect, int select, int extend)
unsigned int *rt;
char *selar;
int a, index;
- int sx = BLI_RCT_SIZE_X(rect) + 1;
- int sy = BLI_RCT_SIZE_Y(rect) + 1;
+ int sx = BLI_rcti_size_x(rect) + 1;
+ int sy = BLI_rcti_size_y(rect) + 1;
me = BKE_mesh_from_object(ob);
diff --git a/source/blender/editors/mesh/editmesh_add.c b/source/blender/editors/mesh/editmesh_add.c
index 8b032bb1a3d..fdaddec5246 100644
--- a/source/blender/editors/mesh/editmesh_add.c
+++ b/source/blender/editors/mesh/editmesh_add.c
@@ -55,9 +55,9 @@
/* ********* add primitive operators ************* */
-static void make_prim_init(bContext *C, const char *idname,
- float *dia, float mat[][4],
- int *state, const float loc[3], const float rot[3], const unsigned int layer)
+static Object *make_prim_init(bContext *C, const char *idname,
+ float *dia, float mat[][4],
+ int *state, const float loc[3], const float rot[3], const unsigned int layer)
{
Object *obedit = CTX_data_edit_object(C);
@@ -74,11 +74,12 @@ static void make_prim_init(bContext *C, const char *idname,
}
*dia = ED_object_new_primitive_matrix(C, obedit, loc, rot, mat);
+
+ return obedit;
}
-static void make_prim_finish(bContext *C, int *state, int enter_editmode)
+static void make_prim_finish(bContext *C, Object *obedit, int *state, int enter_editmode)
{
- Object *obedit = CTX_data_edit_object(C);
BMEditMesh *em = BMEdit_FromObject(obedit);
/* Primitive has all verts selected, use vert select flush
@@ -104,9 +105,7 @@ static int add_primitive_plane_exec(bContext *C, wmOperator *op)
unsigned int layer;
ED_object_add_generic_get_opts(C, op, loc, rot, &enter_editmode, &layer, NULL);
- make_prim_init(C, "Plane", &dia, mat, &state, loc, rot, layer);
-
- obedit = CTX_data_edit_object(C);
+ obedit = make_prim_init(C, "Plane", &dia, mat, &state, loc, rot, layer);
em = BMEdit_FromObject(obedit);
if (!EDBM_op_call_and_selectf(em, op, "vertout",
@@ -115,7 +114,7 @@ static int add_primitive_plane_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
- make_prim_finish(C, &state, enter_editmode);
+ make_prim_finish(C, obedit, &state, enter_editmode);
return OPERATOR_FINISHED;
}
@@ -148,9 +147,7 @@ static int add_primitive_cube_exec(bContext *C, wmOperator *op)
unsigned int layer;
ED_object_add_generic_get_opts(C, op, loc, rot, &enter_editmode, &layer, NULL);
- make_prim_init(C, "Cube", &dia, mat, &state, loc, rot, layer);
-
- obedit = CTX_data_edit_object(C);
+ obedit = make_prim_init(C, "Cube", &dia, mat, &state, loc, rot, layer);
em = BMEdit_FromObject(obedit);
if (!EDBM_op_call_and_selectf(em, op, "vertout", "create_cube mat=%m4 size=%f", mat, dia * 2.0f)) {
@@ -158,7 +155,7 @@ static int add_primitive_cube_exec(bContext *C, wmOperator *op)
}
/* BMESH_TODO make plane side this: M_SQRT2 - plane (diameter of 1.41 makes it unit size) */
- make_prim_finish(C, &state, enter_editmode);
+ make_prim_finish(C, obedit, &state, enter_editmode);
return OPERATOR_FINISHED;
}
@@ -200,9 +197,7 @@ static int add_primitive_circle_exec(bContext *C, wmOperator *op)
cap_tri = (cap_end == 2);
ED_object_add_generic_get_opts(C, op, loc, rot, &enter_editmode, &layer, NULL);
- make_prim_init(C, "Circle", &dia, mat, &state, loc, rot, layer);
-
- obedit = CTX_data_edit_object(C);
+ obedit = make_prim_init(C, "Circle", &dia, mat, &state, loc, rot, layer);
em = BMEdit_FromObject(obedit);
if (!EDBM_op_call_and_selectf(em, op, "vertout",
@@ -213,7 +208,7 @@ static int add_primitive_circle_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
- make_prim_finish(C, &state, enter_editmode);
+ make_prim_finish(C, obedit, &state, enter_editmode);
return OPERATOR_FINISHED;
}
@@ -257,9 +252,7 @@ static int add_primitive_cylinder_exec(bContext *C, wmOperator *op)
cap_tri = (cap_end == 2);
ED_object_add_generic_get_opts(C, op, loc, rot, &enter_editmode, &layer, NULL);
- make_prim_init(C, "Cylinder", &dia, mat, &state, loc, rot, layer);
-
- obedit = CTX_data_edit_object(C);
+ obedit = make_prim_init(C, "Cylinder", &dia, mat, &state, loc, rot, layer);
em = BMEdit_FromObject(obedit);
if (!EDBM_op_call_and_selectf(
@@ -274,7 +267,7 @@ static int add_primitive_cylinder_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
- make_prim_finish(C, &state, enter_editmode);
+ make_prim_finish(C, obedit, &state, enter_editmode);
return OPERATOR_FINISHED;
}
@@ -320,9 +313,7 @@ static int add_primitive_cone_exec(bContext *C, wmOperator *op)
cap_tri = (cap_end == 2);
ED_object_add_generic_get_opts(C, op, loc, rot, &enter_editmode, &layer, NULL);
- make_prim_init(C, "Cone", &dia, mat, &state, loc, rot, layer);
-
- obedit = CTX_data_edit_object(C);
+ obedit = make_prim_init(C, "Cone", &dia, mat, &state, loc, rot, layer);
em = BMEdit_FromObject(obedit);
if (!EDBM_op_call_and_selectf(
@@ -334,7 +325,7 @@ static int add_primitive_cone_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
- make_prim_finish(C, &state, enter_editmode);
+ make_prim_finish(C, obedit, &state, enter_editmode);
return OPERATOR_FINISHED;
}
@@ -379,9 +370,7 @@ static int add_primitive_grid_exec(bContext *C, wmOperator *op)
unsigned int layer;
ED_object_add_generic_get_opts(C, op, loc, rot, &enter_editmode, &layer, NULL);
- make_prim_init(C, "Grid", &dia, mat, &state, loc, rot, layer);
-
- obedit = CTX_data_edit_object(C);
+ obedit = make_prim_init(C, "Grid", &dia, mat, &state, loc, rot, layer);
em = BMEdit_FromObject(obedit);
if (!EDBM_op_call_and_selectf(em, op, "vertout",
@@ -393,7 +382,7 @@ static int add_primitive_grid_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
- make_prim_finish(C, &state, enter_editmode);
+ make_prim_finish(C, obedit, &state, enter_editmode);
return OPERATOR_FINISHED;
}
@@ -436,16 +425,14 @@ static int add_primitive_monkey_exec(bContext *C, wmOperator *op)
if (!view_aligned)
rot[0] += (float)M_PI / 2.0f;
- make_prim_init(C, "Monkey", &dia, mat, &state, loc, rot, layer);
-
- obedit = CTX_data_edit_object(C);
+ obedit = make_prim_init(C, "Monkey", &dia, mat, &state, loc, rot, layer);
em = BMEdit_FromObject(obedit);
if (!EDBM_op_call_and_selectf(em, op, "vertout", "create_monkey mat=%m4", mat)) {
return OPERATOR_CANCELLED;
}
- make_prim_finish(C, &state, enter_editmode);
+ make_prim_finish(C, obedit, &state, enter_editmode);
return OPERATOR_FINISHED;
}
@@ -477,9 +464,7 @@ static int add_primitive_uvsphere_exec(bContext *C, wmOperator *op)
unsigned int layer;
ED_object_add_generic_get_opts(C, op, loc, rot, &enter_editmode, &layer, NULL);
- make_prim_init(C, "Sphere", &dia, mat, &state, loc, rot, layer);
-
- obedit = CTX_data_edit_object(C);
+ obedit = make_prim_init(C, "Sphere", &dia, mat, &state, loc, rot, layer);
em = BMEdit_FromObject(obedit);
if (!EDBM_op_call_and_selectf(em, op, "vertout",
@@ -490,7 +475,7 @@ static int add_primitive_uvsphere_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
- make_prim_finish(C, &state, enter_editmode);
+ make_prim_finish(C, obedit, &state, enter_editmode);
return OPERATOR_FINISHED;
}
@@ -531,9 +516,7 @@ static int add_primitive_icosphere_exec(bContext *C, wmOperator *op)
unsigned int layer;
ED_object_add_generic_get_opts(C, op, loc, rot, &enter_editmode, &layer, NULL);
- make_prim_init(C, "Icosphere", &dia, mat, &state, loc, rot, layer);
-
- obedit = CTX_data_edit_object(C);
+ obedit = make_prim_init(C, "Icosphere", &dia, mat, &state, loc, rot, layer);
em = BMEdit_FromObject(obedit);
if (!EDBM_op_call_and_selectf(
@@ -545,7 +528,7 @@ static int add_primitive_icosphere_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
- make_prim_finish(C, &state, enter_editmode);
+ make_prim_finish(C, obedit, &state, enter_editmode);
return OPERATOR_FINISHED;
}
diff --git a/source/blender/editors/mesh/editmesh_bvh.c b/source/blender/editors/mesh/editmesh_bvh.c
index 0b7d396b696..c249d764ac1 100644
--- a/source/blender/editors/mesh/editmesh_bvh.c
+++ b/source/blender/editors/mesh/editmesh_bvh.c
@@ -309,7 +309,7 @@ static void vertsearchcallback(void *userdata, int index, const float *UNUSED(co
}
}
-BMVert *BMBVH_FindClosestVert(BMBVHTree *tree, const float co[3], float maxdist)
+BMVert *BMBVH_FindClosestVert(BMBVHTree *tree, const float co[3], const float maxdist)
{
BVHTreeNearest hit;
@@ -325,7 +325,7 @@ BMVert *BMBVH_FindClosestVert(BMBVHTree *tree, const float co[3], float maxdist)
float dist, curdist = tree->maxdist, v[3];
int cur = 0, i;
- maxdist = tree->maxdist;
+ /* maxdist = tree->maxdist; */ /* UNUSED */
for (i = 0; i < 3; i++) {
sub_v3_v3v3(v, hit.co, ls[i]->v->co);
diff --git a/source/blender/editors/mesh/editmesh_knife.c b/source/blender/editors/mesh/editmesh_knife.c
index 7ecfb712c18..1dcbf574b44 100644
--- a/source/blender/editors/mesh/editmesh_knife.c
+++ b/source/blender/editors/mesh/editmesh_knife.c
@@ -29,7 +29,9 @@
* \ingroup edmesh
*/
-#define _USE_MATH_DEFINES
+#ifdef _MSC_VER
+# define _USE_MATH_DEFINES
+#endif
#include "MEM_guardedalloc.h"
@@ -222,7 +224,7 @@ static void knife_update_header(bContext *C, KnifeTool_OpData *kcd)
static void knife_project_v3(KnifeTool_OpData *kcd, const float co[3], float sco[3])
{
- ED_view3d_project_float_v3(kcd->ar, co, sco, kcd->projmat);
+ ED_view3d_project_float_v3_m4(kcd->ar, co, sco, kcd->projmat);
}
static void knife_pos_data_clear(KnifePosData *kpd)
@@ -1203,7 +1205,7 @@ static BMEdgeHit *knife_edge_tri_isect(KnifeTool_OpData *kcd, BMBVHTree *bmtree,
}
knife_project_v3(kcd, p, sp);
- view3d_unproject(mats, view, sp[0], sp[1], 0.0f);
+ ED_view3d_unproject(mats, view, sp[0], sp[1], 0.0f);
mul_m4_v3(kcd->ob->imat, view);
if (kcd->cut_through) {
@@ -1386,7 +1388,7 @@ static void knife_input_ray_cast(KnifeTool_OpData *kcd, const int mval_i[2],
mval[1] = (float)mval_i[1];
/* unproject to find view ray */
- view3d_unproject(&mats, r_origin, mval[0], mval[1], 0.0f);
+ ED_view3d_unproject(&mats, r_origin, mval[0], mval[1], 0.0f);
if (kcd->is_ortho) {
negate_v3_v3(r_ray, kcd->vc.rv3d->viewinv[2]);
@@ -1753,6 +1755,9 @@ static int knife_update_active(KnifeTool_OpData *kcd)
return 1;
}
+#define SCANFILL_CUTS 0
+#if SCANFILL_CUTS
+
#define MARK 4
#define DEL 8
#define VERT_ON_EDGE 16
@@ -1761,9 +1766,6 @@ static int knife_update_active(KnifeTool_OpData *kcd)
#define BOUNDARY 128
#define FACE_NEW 256
-#define SCANFILL_CUTS 0
-#if SCANFILL_CUTS
-
typedef struct facenet_entry {
struct facenet_entry *next, *prev;
KnifeEdge *kfe;
diff --git a/source/blender/editors/mesh/editmesh_loopcut.c b/source/blender/editors/mesh/editmesh_loopcut.c
index 60c5244ddbc..8b13cc61d3e 100644
--- a/source/blender/editors/mesh/editmesh_loopcut.c
+++ b/source/blender/editors/mesh/editmesh_loopcut.c
@@ -29,7 +29,9 @@
*/
#include <float.h>
-#define _USE_MATH_DEFINES
+#ifdef _MSC_VER
+# define _USE_MATH_DEFINES
+#endif
#include <math.h>
#include <string.h>
#include <ctype.h>
diff --git a/source/blender/editors/mesh/editmesh_rip.c b/source/blender/editors/mesh/editmesh_rip.c
index 4d4a890300f..53b877f2a6e 100644
--- a/source/blender/editors/mesh/editmesh_rip.c
+++ b/source/blender/editors/mesh/editmesh_rip.c
@@ -61,8 +61,8 @@ static float edbm_rip_rip_edgedist(ARegion *ar, float mat[][4],
{
float vec1[3], vec2[3];
- ED_view3d_project_float_v2(ar, co1, vec1, mat);
- ED_view3d_project_float_v2(ar, co2, vec2, mat);
+ ED_view3d_project_float_v2_m4(ar, co1, vec1, mat);
+ ED_view3d_project_float_v2_m4(ar, co2, vec2, mat);
/* TODO: use dist_squared_to_line_segment_v2() looks like we only ever use for comparison */
return dist_to_line_segment_v2(mvalf, vec1, vec2);
@@ -97,11 +97,11 @@ static float edbm_rip_edge_side_measure(BMEdge *e, BMLoop *e_l,
mid_v3_v3v3(cent, v1_other->co, v2_other->co);
mid_v3_v3v3(mid, e->v1->co, e->v2->co);
- ED_view3d_project_float_v2(ar, cent, cent, projectMat);
- ED_view3d_project_float_v2(ar, mid, mid, projectMat);
+ ED_view3d_project_float_v2_m4(ar, cent, cent, projectMat);
+ ED_view3d_project_float_v2_m4(ar, mid, mid, projectMat);
- ED_view3d_project_float_v2(ar, e->v1->co, e_v1_co, projectMat);
- ED_view3d_project_float_v2(ar, e->v2->co, e_v2_co, projectMat);
+ ED_view3d_project_float_v2_m4(ar, e->v1->co, e_v1_co, projectMat);
+ ED_view3d_project_float_v2_m4(ar, e->v2->co, e_v2_co, projectMat);
sub_v2_v2v2(vec, cent, mid);
normalize_v2(vec);
diff --git a/source/blender/editors/mesh/editmesh_select.c b/source/blender/editors/mesh/editmesh_select.c
index de9b3c5ba05..f6ae661a369 100644
--- a/source/blender/editors/mesh/editmesh_select.c
+++ b/source/blender/editors/mesh/editmesh_select.c
@@ -487,7 +487,6 @@ static void findnearestedge__doClosest(void *userData, BMEdge *eed, int x0, int
vec[0] = eed->v1->co[0] + labda * (eed->v2->co[0] - eed->v1->co[0]);
vec[1] = eed->v1->co[1] + labda * (eed->v2->co[1] - eed->v1->co[1]);
vec[2] = eed->v1->co[2] + labda * (eed->v2->co[2] - eed->v1->co[2]);
- mul_m4_v3(data->vc.obedit->obmat, vec);
if (ED_view3d_clipping_test(data->vc.rv3d, vec, TRUE) == 0) {
data->dist = distance;
@@ -531,7 +530,7 @@ BMEdge *EDBM_edge_find_nearest(ViewContext *vc, int *dist)
data.closest = NULL;
ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d);
- mesh_foreachScreenEdge(vc, findnearestedge__doClosest, &data, 2);
+ mesh_foreachScreenEdge(vc, findnearestedge__doClosest, &data, V3D_CLIP_TEST_REGION);
*dist = data.dist;
return data.closest;
@@ -1058,8 +1057,8 @@ static void mouse_mesh_loop(bContext *C, int mval[2], short extend, short ring)
/* We can't be sure this has already been set... */
ED_view3d_init_mats_rv3d(vc.obedit, vc.rv3d);
- project_float_noclip(vc.ar, eed->v1->co, v1_co);
- project_float_noclip(vc.ar, eed->v2->co, v2_co);
+ ED_view3d_project_float_noclip(vc.ar, eed->v1->co, v1_co);
+ ED_view3d_project_float_noclip(vc.ar, eed->v2->co, v2_co);
#if 0
printf("mouse to v1: %f\nmouse to v2: %f\n", len_squared_v2v2(mvalf, v1_co),
len_squared_v2v2(mvalf, v2_co));
@@ -1087,7 +1086,7 @@ static void mouse_mesh_loop(bContext *C, int mval[2], short extend, short ring)
float co[2], tdist;
BM_face_calc_center_mean(f, cent);
- project_float_noclip(vc.ar, cent, co);
+ ED_view3d_project_float_noclip(vc.ar, cent, co);
tdist = len_squared_v2v2(mvalf, co);
if (tdist < best_dist) {
/* printf("Best face: %p (%f)\n", f, tdist);*/
diff --git a/source/blender/editors/mesh/editmesh_slide.c b/source/blender/editors/mesh/editmesh_slide.c
index 86ea5bc8651..bd1d13f3528 100644
--- a/source/blender/editors/mesh/editmesh_slide.c
+++ b/source/blender/editors/mesh/editmesh_slide.c
@@ -388,10 +388,10 @@ static BMEdge *vtx_slide_nrst_in_frame(VertexSlideOp *vso, const float mval[2])
edge = vso->edge_frame[i];
mul_v3_m4v3(v1_proj, vso->obj->obmat, edge->v1->co);
- project_float_noclip(vso->active_region, v1_proj, v1_proj);
+ ED_view3d_project_float_noclip(vso->active_region, v1_proj, v1_proj);
mul_v3_m4v3(v2_proj, vso->obj->obmat, edge->v2->co);
- project_float_noclip(vso->active_region, v2_proj, v2_proj);
+ ED_view3d_project_float_noclip(vso->active_region, v2_proj, v2_proj);
dist = dist_to_line_segment_v2(mval, v1_proj, v2_proj);
if (dist < min_dist) {
@@ -455,10 +455,10 @@ static void vtx_slide_update(VertexSlideOp *vso, wmEvent *event)
/* Project points onto screen and do interpolation in 2D */
mul_v3_m4v3(start_vtx_proj, vso->obj->obmat, vso->start_vtx->co);
- project_float_noclip(vso->active_region, start_vtx_proj, start_vtx_proj);
+ ED_view3d_project_float_noclip(vso->active_region, start_vtx_proj, start_vtx_proj);
mul_v3_m4v3(edge_other_proj, vso->obj->obmat, other->co);
- project_float_noclip(vso->active_region, edge_other_proj, edge_other_proj);
+ ED_view3d_project_float_noclip(vso->active_region, edge_other_proj, edge_other_proj);
closest_to_line_v2(closest_2d, mval_float, start_vtx_proj, edge_other_proj);
diff --git a/source/blender/editors/mesh/editmesh_tools.c b/source/blender/editors/mesh/editmesh_tools.c
index 9e83742a909..7c700cc9731 100644
--- a/source/blender/editors/mesh/editmesh_tools.c
+++ b/source/blender/editors/mesh/editmesh_tools.c
@@ -163,7 +163,7 @@ void EMBM_project_snap_verts(bContext *C, ARegion *ar, Object *obedit, BMEditMes
float mval[2], vec[3], no_dummy[3];
int dist_dummy;
mul_v3_m4v3(vec, obedit->obmat, eve->co);
- project_float_noclip(ar, vec, mval);
+ ED_view3d_project_float_noclip(ar, vec, mval);
if (snapObjectsContext(C, mval, &dist_dummy, vec, no_dummy, SNAP_NOT_OBEDIT)) {
mul_v3_m4v3(eve->co, obedit->imat, vec);
}
@@ -761,8 +761,8 @@ static int edbm_dupli_extrude_cursor_invoke(bContext *C, wmOperator *op, wmEvent
float co1[3], co2[3];
mul_v3_m4v3(co1, vc.obedit->obmat, eed->v1->co);
mul_v3_m4v3(co2, vc.obedit->obmat, eed->v2->co);
- project_float_noclip(vc.ar, co1, co1);
- project_float_noclip(vc.ar, co2, co2);
+ ED_view3d_project_float_noclip(vc.ar, co1, co1);
+ ED_view3d_project_float_noclip(vc.ar, co2, co2);
/* 2D rotate by 90d while adding.
* (x, y) = (y, -x)
@@ -2526,12 +2526,6 @@ void MESH_OT_solidify(wmOperatorType *ot)
RNA_def_property_ui_range(prop, -10, 10, 0.1, 4);
}
-#define TRAIL_POLYLINE 1 /* For future use, They don't do anything yet */
-#define TRAIL_FREEHAND 2
-#define TRAIL_MIXED 3 /* (1|2) */
-#define TRAIL_AUTO 4
-#define TRAIL_MIDPOINTS 8
-
typedef struct CutCurve {
float x;
float y;
@@ -2776,7 +2770,7 @@ static int edbm_knife_cut_exec(bContext *C, wmOperator *op)
copy_v3_v3(co, bv->co);
co[3] = 1.0f;
mul_m4_v4(obedit->obmat, co);
- project_float(ar, co, scr);
+ ED_view3d_project_float(ar, co, scr);
BLI_ghash_insert(gh, bv, scr);
}
@@ -2858,9 +2852,6 @@ void MESH_OT_knife_cut(wmOperatorType *ot)
static int mesh_separate_tagged(Main *bmain, Scene *scene, Base *base_old, BMesh *bm_old)
{
Base *base_new;
- BMIter iter;
- BMVert *v;
- BMEdge *e;
Object *obedit = base_old->object;
BMesh *bm_new;
@@ -2886,15 +2877,10 @@ static int mesh_separate_tagged(Main *bmain, Scene *scene, Base *base_old, BMesh
BMO_op_callf(bm_old, (BMO_FLAG_DEFAULTS & ~BMO_FLAG_RESPECT_HIDE),
"delete geom=%hvef context=%i", BM_ELEM_TAG, DEL_FACES);
- /* deselect loose data - this used to get deleted */
- BM_ITER_MESH (e, &iter, bm_old, BM_EDGES_OF_MESH) {
- BM_edge_select_set(bm_old, e, FALSE);
- }
-
- /* clean up any loose verts */
- BM_ITER_MESH (v, &iter, bm_old, BM_VERTS_OF_MESH) {
- BM_vert_select_set(bm_old, v, FALSE);
- }
+ /* deselect loose data - this used to get deleted,
+ * we could de-select edges and verts only, but this turns out to be less complicated
+ * since de-selecting all skips selection flushing logic */
+ BM_mesh_elem_hflag_disable_all(bm_old, BM_VERT | BM_EDGE | BM_FACE, BM_ELEM_SELECT, FALSE);
BM_mesh_normals_update(bm_new, FALSE);
@@ -2908,7 +2894,10 @@ static int mesh_separate_tagged(Main *bmain, Scene *scene, Base *base_old, BMesh
static int mesh_separate_selected(Main *bmain, Scene *scene, Base *base_old, BMesh *bm_old)
{
- /* tag -> select */
+ /* we may have tags from previous operators */
+ BM_mesh_elem_hflag_disable_all(bm_old, BM_FACE | BM_EDGE | BM_VERT, BM_ELEM_TAG, FALSE);
+
+ /* sel -> tag */
BM_mesh_elem_hflag_enable_test(bm_old, BM_FACE | BM_EDGE | BM_VERT, BM_ELEM_TAG, TRUE, BM_ELEM_SELECT);
return mesh_separate_tagged(bmain, scene, base_old, bm_old);
@@ -4721,7 +4710,7 @@ static int edbm_bevel_modal(bContext *C, wmOperator *op, wmEvent *event)
mdiff[0] = opdata->mcenter[0] - event->mval[0];
mdiff[1] = opdata->mcenter[1] - event->mval[1];
- factor = -len_v2(mdiff) / opdata->initial_length + 1.0f;
+ factor = opdata->initial_length / -len_v2(mdiff) + 1.0f;
/* Fake shift-transform... */
if (event->shift) {
@@ -5085,9 +5074,9 @@ static int edbm_inset_modal(bContext *C, wmOperator *op, wmEvent *event)
mdiff[1] = opdata->mcenter[1] - event->mval[1];
if (opdata->modify_depth)
- amount = opdata->old_depth + len_v2(mdiff) / opdata->initial_length - 1.0f;
+ amount = opdata->old_depth + opdata->initial_length / len_v2(mdiff) - 1.0f;
else
- amount = opdata->old_thickness - len_v2(mdiff) / opdata->initial_length + 1.0f;
+ amount = opdata->old_thickness - opdata->initial_length / len_v2(mdiff) + 1.0f;
/* Fake shift-transform... */
if (opdata->shift)
diff --git a/source/blender/editors/mesh/editmesh_utils.c b/source/blender/editors/mesh/editmesh_utils.c
index 03e2f2691a8..b844ba0baa2 100644
--- a/source/blender/editors/mesh/editmesh_utils.c
+++ b/source/blender/editors/mesh/editmesh_utils.c
@@ -535,6 +535,16 @@ static void *getEditMesh(bContext *C)
typedef struct UndoMesh {
Mesh me;
int selectmode;
+
+ /** \note
+ * this isn't a prefect solution, if you edit keys and change shapes this works well (fixing [#32442]),
+ * but editing shape keys, going into object mode, removing or changing their order,
+ * then go back into editmode and undo will give issues - where the old index will be out of sync
+ * with the new object index.
+ *
+ * There are a few ways this could be made to work but for now its a known limitation with mixing
+ * object and editmode operations - Campbell */
+ int shapenr;
} UndoMesh;
/* undo simply makes copies of a bmesh */
@@ -546,13 +556,14 @@ static void *editbtMesh_to_undoMesh(void *emv, void *obdata)
UndoMesh *um = MEM_callocN(sizeof(UndoMesh), "undo Mesh");
/* make sure shape keys work */
- um->me.key = obme->key ? copy_key_nolib(obme->key) : NULL;
+ um->me.key = obme->key ? BKE_key_copy_nolib(obme->key) : NULL;
/* BM_mesh_validate(em->bm); */ /* for troubleshooting */
BM_mesh_bm_to_me(em->bm, &um->me, FALSE);
um->selectmode = em->selectmode;
+ um->shapenr = em->bm->shapenr;
return um;
}
@@ -564,7 +575,7 @@ static void undoMesh_to_editbtMesh(void *umv, void *em_v, void *UNUSED(obdata))
UndoMesh *um = umv;
BMesh *bm;
- ob->shapenr = em->bm->shapenr;
+ ob->shapenr = em->bm->shapenr = um->shapenr;
EDBM_mesh_free(em);
diff --git a/source/blender/editors/mesh/mesh_data.c b/source/blender/editors/mesh/mesh_data.c
index 09d89a961e4..a52c8d47ecd 100644
--- a/source/blender/editors/mesh/mesh_data.c
+++ b/source/blender/editors/mesh/mesh_data.c
@@ -47,6 +47,8 @@
#include "BLI_array.h"
#include "BLI_math.h"
#include "BLI_edgehash.h"
+#include "BLI_linklist.h"
+#include "BLI_listbase.h"
#include "BKE_context.h"
#include "BKE_depsgraph.h"
@@ -74,6 +76,64 @@
#include "mesh_intern.h"
+static CustomData *mesh_customdata_get_type(Mesh *me, const char htype, int *r_tot)
+{
+ CustomData *data;
+ BMesh *bm = (me->edit_btmesh) ? me->edit_btmesh->bm : NULL;
+ int tot;
+
+ /* this */
+ switch (htype) {
+ case BM_VERT:
+ if (bm) {
+ data = &bm->vdata;
+ tot = bm->totvert;
+ }
+ else {
+ data = &me->vdata;
+ tot = me->totvert;
+ }
+ break;
+ case BM_EDGE:
+ if (bm) {
+ data = &bm->edata;
+ tot = bm->totedge;
+ }
+ else {
+ data = &me->edata;
+ tot = me->totedge;
+ }
+ break;
+ case BM_LOOP:
+ if (bm) {
+ data = &bm->ldata;
+ tot = bm->totloop;
+ }
+ else {
+ data = &me->ldata;
+ tot = me->totloop;
+ }
+ break;
+ case BM_FACE:
+ if (bm) {
+ data = &bm->pdata;
+ tot = bm->totface;
+ }
+ else {
+ data = &me->pdata;
+ tot = me->totpoly;
+ }
+ break;
+ default:
+ BLI_assert(0);
+ tot = 0;
+ data = NULL;
+ }
+
+ *r_tot = tot;
+ return data;
+}
+
#define GET_CD_DATA(me, data) (me->edit_btmesh ? &me->edit_btmesh->bm->data : &me->data)
static void delete_customdata_layer(bContext *C, Object *ob, CustomDataLayer *layer)
{
@@ -85,24 +145,10 @@ static void delete_customdata_layer(bContext *C, Object *ob, CustomDataLayer *la
int i, actindex, rndindex, cloneindex, stencilindex, tot;
if (layer->type == CD_MLOOPCOL || layer->type == CD_MLOOPUV) {
- if (me->edit_btmesh) {
- data = &me->edit_btmesh->bm->ldata;
- tot = me->edit_btmesh->bm->totloop;
- }
- else {
- data = &me->ldata;
- tot = me->totloop;
- }
+ data = mesh_customdata_get_type(me, BM_LOOP, &tot);
}
else {
- if (me->edit_btmesh) {
- data = &me->edit_btmesh->bm->pdata;
- tot = me->edit_btmesh->bm->totface;
- }
- else {
- data = &me->pdata;
- tot = me->totpoly;
- }
+ data = mesh_customdata_get_type(me, BM_FACE, &tot);
}
index = CustomData_get_layer_index(data, type);
@@ -701,22 +747,20 @@ void MESH_OT_vertex_color_remove(wmOperatorType *ot)
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
-/*********************** sticky operators ************************/
+/* *** CustomData clear functions, we need an operator for each *** */
-static int mesh_sticky_add_exec(bContext *C, wmOperator *UNUSED(op))
+static int mesh_customdata_clear_exec__internal(bContext *C,
+ char htype, int type)
{
- Scene *scene = CTX_data_scene(C);
- View3D *v3d = CTX_wm_view3d(C);
- Object *ob = ED_object_context(C);
- Mesh *me = ob->data;
+ Object *obedit = ED_object_context(C);
+ Mesh *me = obedit->data;
- /* why is this commented out? */
-#if 0
- if (me->msticky)
- return OPERATOR_CANCELLED;
-#endif
+ int tot;
+ CustomData *data = mesh_customdata_get_type(me, htype, &tot);
- RE_make_sticky(scene, v3d);
+ BLI_assert(CustomData_layertype_is_singleton(type) == TRUE);
+
+ CustomData_free_layers(data, type, tot);
DAG_id_tag_update(&me->id, 0);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, me);
@@ -724,48 +768,79 @@ static int mesh_sticky_add_exec(bContext *C, wmOperator *UNUSED(op))
return OPERATOR_FINISHED;
}
-void MESH_OT_sticky_add(wmOperatorType *ot)
+/* Clear Mask */
+static int mesh_customdata_clear_mask_poll(bContext *C)
+{
+ Object *ob = ED_object_context(C);
+ if (ob && ob->type == OB_MESH) {
+ Mesh *me = ob->data;
+
+ /* special case - can't run this if we're in sculpt mode */
+ if (ob->mode & OB_MODE_SCULPT) {
+ return FALSE;
+ }
+
+ if (me->id.lib == NULL) {
+ CustomData *data = GET_CD_DATA(me, vdata);
+ if (CustomData_has_layer(data, CD_PAINT_MASK)) {
+ return TRUE;
+ }
+ }
+ }
+ return FALSE;
+}
+static int mesh_customdata_clear_mask_exec(bContext *C, wmOperator *UNUSED(op))
+{
+ return mesh_customdata_clear_exec__internal(C, BM_VERT, CD_PAINT_MASK);
+}
+
+void MESH_OT_customdata_clear_mask(wmOperatorType *ot)
{
+
/* identifiers */
- ot->name = "Add Sticky";
- ot->description = "Add sticky UV texture layer";
- ot->idname = "MESH_OT_sticky_add";
-
+ ot->name = "Clear Sculpt-Mask Data";
+ ot->idname = "MESH_OT_customdata_clear_mask";
+ ot->description = "Clear vertex sculpt masking data from the mesh";
+
/* api callbacks */
- ot->poll = layers_poll;
- ot->exec = mesh_sticky_add_exec;
+ ot->exec = mesh_customdata_clear_mask_exec;
+ ot->poll = mesh_customdata_clear_mask_poll;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
-static int mesh_sticky_remove_exec(bContext *C, wmOperator *UNUSED(op))
+/* Clear Skin */
+static int mesh_customdata_clear_skin_poll(bContext *C)
{
Object *ob = ED_object_context(C);
- Mesh *me = ob->data;
- if (!me->msticky)
- return OPERATOR_CANCELLED;
-
- CustomData_free_layer_active(&me->vdata, CD_MSTICKY, me->totvert);
- me->msticky = NULL;
-
- DAG_id_tag_update(&me->id, 0);
- WM_event_add_notifier(C, NC_GEOM | ND_DATA, me);
-
- return OPERATOR_FINISHED;
+ if (ob && ob->type == OB_MESH) {
+ Mesh *me = ob->data;
+ if (me->id.lib == NULL) {
+ CustomData *data = GET_CD_DATA(me, vdata);
+ if (CustomData_has_layer(data, CD_MVERT_SKIN)) {
+ return TRUE;
+ }
+ }
+ }
+ return FALSE;
+}
+static int mesh_customdata_clear_skin_exec(bContext *C, wmOperator *UNUSED(op))
+{
+ return mesh_customdata_clear_exec__internal(C, BM_VERT, CD_MVERT_SKIN);
}
-void MESH_OT_sticky_remove(wmOperatorType *ot)
+void MESH_OT_customdata_clear_skin(wmOperatorType *ot)
{
/* identifiers */
- ot->name = "Remove Sticky";
- ot->description = "Remove sticky UV texture layer";
- ot->idname = "MESH_OT_sticky_remove";
-
+ ot->name = "Clear Skin Data";
+ ot->idname = "MESH_OT_customdata_clear_skin";
+ ot->description = "Clear vertex skin layer";
+
/* api callbacks */
- ot->poll = layers_poll;
- ot->exec = mesh_sticky_remove_exec;
+ ot->exec = mesh_customdata_clear_skin_exec;
+ ot->poll = mesh_customdata_clear_skin_poll;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
diff --git a/source/blender/editors/mesh/mesh_intern.h b/source/blender/editors/mesh/mesh_intern.h
index aed57141c2a..b68c1836992 100644
--- a/source/blender/editors/mesh/mesh_intern.h
+++ b/source/blender/editors/mesh/mesh_intern.h
@@ -189,8 +189,10 @@ void MESH_OT_uv_texture_add(struct wmOperatorType *ot);
void MESH_OT_uv_texture_remove(struct wmOperatorType *ot);
void MESH_OT_vertex_color_add(struct wmOperatorType *ot);
void MESH_OT_vertex_color_remove(struct wmOperatorType *ot);
-void MESH_OT_sticky_add(struct wmOperatorType *ot);
-void MESH_OT_sticky_remove(struct wmOperatorType *ot);
+/* no create_mask yet */
+void MESH_OT_customdata_clear_mask(struct wmOperatorType *ot);
+void MESH_OT_customdata_clear_skin(struct wmOperatorType *ot);
+
void MESH_OT_drop_named_image(struct wmOperatorType *ot);
/* ************* bmesh_tools.c ***********/
diff --git a/source/blender/editors/mesh/mesh_ops.c b/source/blender/editors/mesh/mesh_ops.c
index 7f73851f2a8..ccf91958e08 100644
--- a/source/blender/editors/mesh/mesh_ops.c
+++ b/source/blender/editors/mesh/mesh_ops.c
@@ -136,7 +136,6 @@ void ED_operatortypes_mesh(void)
WM_operatortype_append(MESH_OT_vertices_smooth);
WM_operatortype_append(MESH_OT_noise);
WM_operatortype_append(MESH_OT_flip_normals);
- //WM_operatortype_append(MESH_OT_knife_cut);
WM_operatortype_append(MESH_OT_rip);
WM_operatortype_append(MESH_OT_blend_from_shape);
WM_operatortype_append(MESH_OT_shape_propagate_to_all);
@@ -145,8 +144,8 @@ void ED_operatortypes_mesh(void)
WM_operatortype_append(MESH_OT_uv_texture_remove);
WM_operatortype_append(MESH_OT_vertex_color_add);
WM_operatortype_append(MESH_OT_vertex_color_remove);
- WM_operatortype_append(MESH_OT_sticky_add);
- WM_operatortype_append(MESH_OT_sticky_remove);
+ WM_operatortype_append(MESH_OT_customdata_clear_mask);
+ WM_operatortype_append(MESH_OT_customdata_clear_skin);
WM_operatortype_append(MESH_OT_drop_named_image);
WM_operatortype_append(MESH_OT_edgering_select);
diff --git a/source/blender/editors/mesh/meshtools.c b/source/blender/editors/mesh/meshtools.c
index a7467ee4c79..f2b7a2e9c22 100644
--- a/source/blender/editors/mesh/meshtools.c
+++ b/source/blender/editors/mesh/meshtools.c
@@ -104,7 +104,7 @@ int join_mesh_exec(bContext *C, wmOperator *op)
MLoop *mloop = NULL;
Key *key, *nkey = NULL;
KeyBlock *kb, *okb, *kbn;
- float imat[4][4], cmat[4][4], *fp1, *fp2, curpos;
+ float imat[4][4], cmat[4][4], *fp1, *fp2;
int a, b, totcol, totmat = 0, totedge = 0, totvert = 0, ok = 0;
int totloop = 0, totpoly = 0, vertofs, *matmap = NULL;
int i, j, index, haskey = 0, edgeofs, loopofs, polyofs;
@@ -196,7 +196,7 @@ int join_mesh_exec(bContext *C, wmOperator *op)
}
else if (haskey) {
/* add a new key-block and add to the mesh */
- key = me->key = add_key((ID *)me);
+ key = me->key = BKE_key_add((ID *)me);
key->type = KEY_RELATIVE;
}
@@ -243,29 +243,29 @@ int join_mesh_exec(bContext *C, wmOperator *op)
/* if this mesh has shapekeys, check if destination mesh already has matching entries too */
if (me->key && key) {
- for (kb = me->key->block.first; kb; kb = kb->next) {
+ /* for remapping KeyBlock.relative */
+ int *index_map = MEM_mallocN(sizeof(int) * me->key->totkey, __func__);
+ KeyBlock **kb_map = MEM_mallocN(sizeof(KeyBlock *) * me->key->totkey, __func__);
+
+ for (kb = me->key->block.first, i = 0; kb; kb = kb->next, i++) {
+ BLI_assert(i < me->key->totkey);
+
+ kbn = BKE_keyblock_find_name(key, kb->name);
/* if key doesn't exist in destination mesh, add it */
- if (key_get_named_keyblock(key, kb->name) == NULL) {
- /* copy this existing one over to the new shapekey block */
- kbn = MEM_dupallocN(kb);
- kbn->prev = kbn->next = NULL;
-
+ if (kbn) {
+ index_map[i] = BLI_findindex(&key->block, kbn);
+ }
+ else {
+ index_map[i] = key->totkey;
+
+ kbn = BKE_keyblock_add(key, kb->name);
+
+ BKE_keyblock_copy_settings(kbn, kb);
+
/* adjust settings to fit (allocate a new data-array) */
kbn->data = MEM_callocN(sizeof(float) * 3 * totvert, "joined_shapekey");
- kbn->totelem = totvert;
- kbn->weights = NULL;
-
- okb = key->block.last;
- curpos = (okb) ? okb->pos : -0.1f;
- if (key->type == KEY_RELATIVE)
- kbn->pos = curpos + 0.1f;
- else
- kbn->pos = curpos;
-
- BLI_addtail(&key->block, kbn);
- key->totkey++;
- if (key->totkey == 1) key->refkey = kbn;
-
+ kbn->totelem = totvert;
+
/* XXX 2.5 Animato */
#if 0
/* also, copy corresponding ipo-curve to ipo-block if applicable */
@@ -275,13 +275,26 @@ int join_mesh_exec(bContext *C, wmOperator *op)
}
#endif
}
+
+ kb_map[i] = kbn;
}
+
+ /* remap relative index values */
+ for (kb = me->key->block.first, i = 0; kb; kb = kb->next, i++) {
+ if (LIKELY(kb->relative < me->key->totkey)) { /* sanity check, should always be true */
+ kb_map[i]->relative = index_map[kb->relative];
+ }
+ }
+
+ MEM_freeN(index_map);
+ MEM_freeN(kb_map);
}
}
}
}
CTX_DATA_END;
-
+
+
/* setup new data for destination mesh */
memset(&vdata, 0, sizeof(vdata));
memset(&edata, 0, sizeof(edata));
@@ -356,7 +369,8 @@ int join_mesh_exec(bContext *C, wmOperator *op)
fp1 = ((float *)kb->data) + (vertofs * 3);
/* check if this mesh has such a shapekey */
- okb = key_get_named_keyblock(me->key, kb->name);
+ okb = me->key ? BKE_keyblock_find_name(me->key, kb->name) : NULL;
+
if (okb) {
/* copy this mesh's shapekey to the destination shapekey (need to transform first) */
fp2 = ((float *)(okb->data));
@@ -386,7 +400,7 @@ int join_mesh_exec(bContext *C, wmOperator *op)
fp1 = ((float *)kb->data) + (vertofs * 3);
/* check if this was one of the original shapekeys */
- okb = key_get_named_keyblock(nkey, kb->name);
+ okb = BKE_keyblock_find_name(nkey, kb->name);
if (okb) {
/* copy this mesh's shapekey to the destination shapekey */
fp2 = ((float *)(okb->data));
@@ -427,8 +441,8 @@ int join_mesh_exec(bContext *C, wmOperator *op)
if ((mmd = get_multires_modifier(scene, base->object, TRUE))) {
ED_object_iter_other(bmain, base->object, TRUE,
- ED_object_multires_update_totlevels_cb,
- &mmd->totlvl);
+ ED_object_multires_update_totlevels_cb,
+ &mmd->totlvl);
}
}
@@ -548,6 +562,12 @@ int join_mesh_exec(bContext *C, wmOperator *op)
MEM_freeN(nkey);
}
+ /* ensure newly inserted keys are time sorted */
+ if (key && (key->type != KEY_RELATIVE)) {
+ BKE_key_sort(key);
+ }
+
+
DAG_scene_sort(bmain, scene); // removed objects, need to rebuild dag before editmode call
#if 0
@@ -607,12 +627,12 @@ int join_mesh_shapes_exec(bContext *C, wmOperator *op)
}
if (key == NULL) {
- key = me->key = add_key((ID *)me);
+ key = me->key = BKE_key_add((ID *)me);
key->type = KEY_RELATIVE;
/* first key added, so it was the basis. initialize it with the existing mesh */
- kb = add_keyblock(key, NULL);
- mesh_to_key(me, kb);
+ kb = BKE_keyblock_add(key, NULL);
+ BKE_key_convert_from_mesh(me, kb);
}
/* now ready to add new keys from selected meshes */
@@ -628,7 +648,7 @@ int join_mesh_shapes_exec(bContext *C, wmOperator *op)
if (!dm) continue;
- kb = add_keyblock(key, base->object->id.name + 2);
+ kb = BKE_keyblock_add(key, base->object->id.name + 2);
DM_to_meshkey(dm, me, kb);
@@ -709,9 +729,9 @@ static void mesh_octree_add_nodes(MocNode **basetable, const float co[3], const
float fx, fy, fz;
int vx, vy, vz;
- if (!finite(co[0]) ||
- !finite(co[1]) ||
- !finite(co[2]))
+ if ((finite(co[0]) == FALSE) ||
+ (finite(co[1]) == FALSE) ||
+ (finite(co[2]) == FALSE))
{
return;
}
@@ -940,9 +960,9 @@ static BMVert *editbmesh_get_x_mirror_vert_spatial(Object *ob, BMEditMesh *em, c
intptr_t poinval;
/* ignore nan verts */
- if (!finite(co[0]) ||
- !finite(co[1]) ||
- !finite(co[2]))
+ if ((finite(co[0]) == FALSE) ||
+ (finite(co[1]) == FALSE) ||
+ (finite(co[2]) == FALSE))
{
return NULL;
}
@@ -1217,7 +1237,7 @@ int ED_mesh_pick_face_vert(bContext *C, Mesh *me, Object *ob, const int mval[2],
const int v_idx = me->mloop[mp->loopstart + fidx].v;
dm->getVertCo(dm, v_idx, co);
mul_m4_v3(ob->obmat, co);
- project_float_noclip(ar, co, sco);
+ ED_view3d_project_float_noclip(ar, co, sco);
len = len_squared_v2v2(mval_f, sco);
if (len < len_best) {
len_best = len;