replace most uses of ED_view3d_project_float_noclip() with ED_view3d_project_float_global/object

This commit is contained in:
Campbell Barton 2012-10-05 03:57:56 +00:00
parent b9113f205c
commit 5770e44f43
6 changed files with 82 additions and 64 deletions

@ -174,7 +174,7 @@ void ED_spacetypes_init(void);
/* editmesh_tools.c (could be moved) */ /* editmesh_tools.c (could be moved) */
void EMBM_project_snap_verts(struct bContext *C, struct ARegion *ar, struct Object *obedit, struct BMEditMesh *em); void EMBM_project_snap_verts(struct bContext *C, struct ARegion *ar, struct BMEditMesh *em);
/* editface.c */ /* editface.c */

@ -381,22 +381,23 @@ static BMEdge *vtx_slide_nrst_in_frame(VertexSlideOp *vso, const float mval[2])
BMEdge *edge = NULL; BMEdge *edge = NULL;
float v1_proj[3], v2_proj[3]; float v1_proj[3], v2_proj[3];
float dist = 0;
float min_dist = FLT_MAX; float min_dist = FLT_MAX;
for (i = 0; i < vso->disk_edges; i++) { for (i = 0; i < vso->disk_edges; i++) {
edge = vso->edge_frame[i]; edge = vso->edge_frame[i];
mul_v3_m4v3(v1_proj, vso->obj->obmat, edge->v1->co); mul_v3_m4v3(v1_proj, vso->obj->obmat, edge->v1->co);
ED_view3d_project_float_noclip(vso->active_region, v1_proj, v1_proj);
mul_v3_m4v3(v2_proj, vso->obj->obmat, edge->v2->co); mul_v3_m4v3(v2_proj, vso->obj->obmat, edge->v2->co);
ED_view3d_project_float_noclip(vso->active_region, v2_proj, v2_proj);
dist = dist_to_line_segment_v2(mval, v1_proj, v2_proj); /* we could use ED_view3d_project_float_object here, but for now dont since we dont have the context */
if (dist < min_dist) { if ((ED_view3d_project_float_global(vso->active_region, v1_proj, v1_proj, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_SUCCESS) &&
min_dist = dist; (ED_view3d_project_float_global(vso->active_region, v2_proj, v2_proj, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_SUCCESS))
cl_edge = edge; {
const float dist = dist_to_line_segment_v2(mval, v1_proj, v2_proj);
if (dist < min_dist) {
min_dist = dist;
cl_edge = edge;
}
} }
} }
} }
@ -448,17 +449,21 @@ static void vtx_slide_update(VertexSlideOp *vso, wmEvent *event)
/* Calculate interpolation value for preview */ /* Calculate interpolation value for preview */
float t_val; float t_val;
float mval_float[] = { (float)event->mval[0], (float)event->mval[1]}; float mval_float[2] = { (float)event->mval[0], (float)event->mval[1]};
float closest_2d[2]; float closest_2d[2];
other = BM_edge_other_vert(edge, vso->start_vtx); other = BM_edge_other_vert(edge, vso->start_vtx);
/* Project points onto screen and do interpolation in 2D */ /* Project points onto screen and do interpolation in 2D */
mul_v3_m4v3(start_vtx_proj, vso->obj->obmat, vso->start_vtx->co); mul_v3_m4v3(start_vtx_proj, vso->obj->obmat, vso->start_vtx->co);
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); mul_v3_m4v3(edge_other_proj, vso->obj->obmat, other->co);
ED_view3d_project_float_noclip(vso->active_region, edge_other_proj, edge_other_proj);
if ((ED_view3d_project_float_global(vso->active_region, edge_other_proj, edge_other_proj, V3D_PROJ_TEST_NOP) != V3D_PROJ_RET_SUCCESS) ||
(ED_view3d_project_float_global(vso->active_region, start_vtx_proj, start_vtx_proj, V3D_PROJ_TEST_NOP) != V3D_PROJ_RET_SUCCESS))
{
/* not much we can do here */
return;
}
closest_to_line_v2(closest_2d, mval_float, start_vtx_proj, edge_other_proj); closest_to_line_v2(closest_2d, mval_float, start_vtx_proj, edge_other_proj);
@ -470,7 +475,7 @@ static void vtx_slide_update(VertexSlideOp *vso, wmEvent *event)
if (edge_len <= 0.0f) if (edge_len <= 0.0f)
edge_len = VTX_SLIDE_SNAP_THRSH; edge_len = VTX_SLIDE_SNAP_THRSH;
edge_len = (len_v3v3(edge->v1->co, edge->v2->co) * VTX_SLIDE_SNAP_THRSH) / edge_len; edge_len = (BM_edge_calc_length(edge) * VTX_SLIDE_SNAP_THRSH) / edge_len;
vso->snap_threshold = edge_len; vso->snap_threshold = edge_len;

@ -153,19 +153,22 @@ void MESH_OT_subdivide(wmOperatorType *ot)
} }
void EMBM_project_snap_verts(bContext *C, ARegion *ar, Object *obedit, BMEditMesh *em) void EMBM_project_snap_verts(bContext *C, ARegion *ar, BMEditMesh *em)
{ {
Object *obedit = em->ob;
BMIter iter; BMIter iter;
BMVert *eve; BMVert *eve;
ED_view3d_init_mats_rv3d(obedit, ar->regiondata);
BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) { BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) {
if (BM_elem_flag_test(eve, BM_ELEM_SELECT)) { if (BM_elem_flag_test(eve, BM_ELEM_SELECT)) {
float mval[2], vec[3], no_dummy[3]; float mval[2], co_proj[3], no_dummy[3];
int dist_dummy; int dist_dummy;
mul_v3_m4v3(vec, obedit->obmat, eve->co); if (ED_view3d_project_float_object(ar, eve->co, mval, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_SUCCESS) {
ED_view3d_project_float_noclip(ar, vec, mval); if (snapObjectsContext(C, mval, &dist_dummy, co_proj, no_dummy, SNAP_NOT_OBEDIT)) {
if (snapObjectsContext(C, mval, &dist_dummy, vec, no_dummy, SNAP_NOT_OBEDIT)) { mul_v3_m4v3(eve->co, obedit->imat, co_proj);
mul_v3_m4v3(eve->co, obedit->imat, vec); }
} }
} }
} }
@ -731,7 +734,10 @@ static int edbm_dupli_extrude_cursor_invoke(bContext *C, wmOperator *op, wmEvent
short use_proj; short use_proj;
em_setup_viewcontext(C, &vc); em_setup_viewcontext(C, &vc);
ED_view3d_init_mats_rv3d(vc.obedit, vc.rv3d);
use_proj = ((vc.scene->toolsettings->snap_flag & SCE_SNAP) && use_proj = ((vc.scene->toolsettings->snap_flag & SCE_SNAP) &&
(vc.scene->toolsettings->snap_mode == SCE_SNAP_MODE_FACE)); (vc.scene->toolsettings->snap_mode == SCE_SNAP_MODE_FACE));
@ -760,26 +766,26 @@ static int edbm_dupli_extrude_cursor_invoke(bContext *C, wmOperator *op, wmEvent
BM_ITER_MESH (eed, &iter, vc.em->bm, BM_EDGES_OF_MESH) { BM_ITER_MESH (eed, &iter, vc.em->bm, BM_EDGES_OF_MESH) {
if (BM_elem_flag_test(eed, BM_ELEM_SELECT)) { if (BM_elem_flag_test(eed, BM_ELEM_SELECT)) {
float co1[3], co2[3]; 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);
ED_view3d_project_float_noclip(vc.ar, co1, co1);
ED_view3d_project_float_noclip(vc.ar, co2, co2);
/* 2D rotate by 90d while adding. if ((ED_view3d_project_float_object(vc.ar, eed->v1->co, co1, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_SUCCESS) &&
* (x, y) = (y, -x) (ED_view3d_project_float_object(vc.ar, eed->v2->co, co2, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_SUCCESS))
* {
* accumulate the screenspace normal in 2D, /* 2D rotate by 90d while adding.
* with screenspace edge length weighting the result. */ * (x, y) = (y, -x)
if (line_point_side_v2(co1, co2, mval_f) >= 0.0f) { *
nor[0] += (co1[1] - co2[1]); * accumulate the screenspace normal in 2D,
nor[1] += -(co1[0] - co2[0]); * with screenspace edge length weighting the result. */
} if (line_point_side_v2(co1, co2, mval_f) >= 0.0f) {
else { nor[0] += (co1[1] - co2[1]);
nor[0] += (co2[1] - co1[1]); nor[1] += -(co1[0] - co2[0]);
nor[1] += -(co2[0] - co1[0]); }
else {
nor[0] += (co2[1] - co1[1]);
nor[1] += -(co2[0] - co1[0]);
}
done = TRUE;
} }
} }
done = TRUE;
} }
if (done) { if (done) {
@ -836,7 +842,7 @@ static int edbm_dupli_extrude_cursor_invoke(bContext *C, wmOperator *op, wmEvent
/* also project the source, for retopo workflow */ /* also project the source, for retopo workflow */
if (use_proj) if (use_proj)
EMBM_project_snap_verts(C, vc.ar, vc.obedit, vc.em); EMBM_project_snap_verts(C, vc.ar, vc.em);
} }
edbm_extrude_edge(vc.obedit, vc.em, BM_ELEM_SELECT, nor); edbm_extrude_edge(vc.obedit, vc.em, BM_ELEM_SELECT, nor);
@ -869,7 +875,7 @@ static int edbm_dupli_extrude_cursor_invoke(bContext *C, wmOperator *op, wmEvent
} }
if (use_proj) if (use_proj)
EMBM_project_snap_verts(C, vc.ar, vc.obedit, vc.em); EMBM_project_snap_verts(C, vc.ar, vc.em);
/* This normally happens when pushing undo but modal operators /* This normally happens when pushing undo but modal operators
* like this one don't push undo data until after modal mode is * like this one don't push undo data until after modal mode is

@ -1237,11 +1237,12 @@ 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; const int v_idx = me->mloop[mp->loopstart + fidx].v;
dm->getVertCo(dm, v_idx, co); dm->getVertCo(dm, v_idx, co);
mul_m4_v3(ob->obmat, co); mul_m4_v3(ob->obmat, co);
ED_view3d_project_float_noclip(ar, co, sco); if (ED_view3d_project_float_global(ar, co, sco, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_SUCCESS) {
len = len_squared_v2v2(mval_f, sco); len = len_squared_v2v2(mval_f, sco);
if (len < len_best) { if (len < len_best) {
len_best = len; len_best = len;
v_idx_best = v_idx; v_idx_best = v_idx;
}
} }
} while (fidx--); } while (fidx--);
} }

@ -846,20 +846,22 @@ static int sample_backbuf_area(ViewContext *vc, int *indexar, int totface, int x
static float calc_vp_strength_dl(VPaint *vp, ViewContext *vc, const float vert_nor[3], static float calc_vp_strength_dl(VPaint *vp, ViewContext *vc, const float vert_nor[3],
const float mval[2], const float brush_size_pressure) const float mval[2], const float brush_size_pressure)
{ {
Brush *brush = paint_brush(&vp->paint); float vertco[2];
float dist_squared;
float vertco[2], delta[2];
ED_view3d_project_float_noclip(vc->ar, vert_nor, vertco); if (ED_view3d_project_float_global(vc->ar, vert_nor, vertco, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_SUCCESS) {
sub_v2_v2v2(delta, mval, vertco); float delta[2];
dist_squared = dot_v2v2(delta, delta); /* len squared */ float dist_squared;
if (dist_squared > brush_size_pressure * brush_size_pressure) {
return 0.0f; sub_v2_v2v2(delta, mval, vertco);
} dist_squared = dot_v2v2(delta, delta); /* len squared */
else { if (dist_squared <= brush_size_pressure * brush_size_pressure) {
const float dist = sqrtf(dist_squared); Brush *brush = paint_brush(&vp->paint);
return BKE_brush_curve_strength_clamp(brush, dist, brush_size_pressure); const float dist = sqrtf(dist_squared);
return BKE_brush_curve_strength_clamp(brush, dist, brush_size_pressure);
}
} }
return 0.0f;
} }
static float calc_vp_alpha_dl(VPaint *vp, ViewContext *vc, static float calc_vp_alpha_dl(VPaint *vp, ViewContext *vc,

@ -351,7 +351,11 @@ void projectFloatView(TransInfo *t, const float vec[3], float adr[2])
case SPACE_VIEW3D: case SPACE_VIEW3D:
{ {
if (t->ar->regiontype == RGN_TYPE_WINDOW) { if (t->ar->regiontype == RGN_TYPE_WINDOW) {
ED_view3d_project_float_noclip(t->ar, vec, adr); if (ED_view3d_project_float_global(t->ar, vec, adr, V3D_PROJ_TEST_NOP) != V3D_PROJ_RET_SUCCESS) {
/* XXX, 2.64 and prior did this, weak! */
adr[0] = t->ar->winx / 2.0f;
adr[1] = t->ar->winy / 2.0f;
}
return; return;
} }
break; break;
@ -4793,12 +4797,12 @@ static void calcNonProportionalEdgeSlide(TransInfo *t, SlideData *sld, const flo
sv->edge_len = len_v3v3(dw_p, up_p); sv->edge_len = len_v3v3(dw_p, up_p);
mul_v3_m4v3(v_proj, t->obedit->obmat, sv->v->co); mul_v3_m4v3(v_proj, t->obedit->obmat, sv->v->co);
ED_view3d_project_float_noclip(t->ar, v_proj, v_proj); if (ED_view3d_project_float_global(t->ar, v_proj, v_proj, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_SUCCESS) {
dist = len_squared_v2v2(mval, v_proj);
dist = len_squared_v2v2(mval, v_proj); if (dist < min_dist) {
if (dist < min_dist) { min_dist = dist;
min_dist = dist; sld->curr_sv_index = i;
sld->curr_sv_index = i; }
} }
} }
} }